// import { useStore } from 'vuex';
// import Cookies from 'js-cookie';
// import { useRoute } from 'vue-router';
// import { reactive } from '@vue/reactivity';
// import { onMounted } from '@vue/runtime-core';
import { apiService } from '../../api/apiService';
import { capiDelCommonFile, capiCommonFile } from '../../api/server';
import { showSuccess, showError } from '../../util/MessageDeal';
import { selfI18n } from '@/i18n';
export function useAttachmentFile () {
    // 删除文件
    const removeFile = (file, callback) => {
        apiService({
            api: capiDelCommonFile,
            param: {
                filename: file.filename,
                md5name: file.md5name
            },
            success: data => {
                showSuccess(selfI18n('op_success'));
                callback && callback();
            }
        });
    };
    // 上传文件
    const uploadFile = (file) => {
        const param = new FormData();
        param.append('bucketname', 'ncmaintain');
        param.append('filename', file.name);
        param.append('file', file);
        apiService({
            api: capiCommonFile,
            param: param,
            success: data => {
                this.filedata.push(data.value);
                if (this.$refs.upload) {
                    this.$refs.upload.value = '';
                }
                showSuccess(selfI18n('wp_Uploaded_successfully'));
                this.$emit('listchange', this.filedata);
            },
            fail: data => {
                showError(selfI18n('wp_Upload_failed'));
                console.log('失败');
                console.log(data);
                this.filedata.pop();
                if (this.$refs.upload) {
                    this.$refs.upload.value = '';
                }
            },
            error: data => {
                showError(selfI18n('wp_Upload_failed'));
                console.log('失败');
                console.log(data);
                this.filedata.pop();
                if (this.$refs.upload) {
                    this.$refs.upload.value = '';
                }
            }
        });
    };
    return {
        removeFile,
        uploadFile
    };
}
